package com.springboot.myspringbootframework.domain.user.application;

import com.springboot.myspringbootframework.domain.user.api.UserApi;
import com.springboot.myspringbootframework.domain.user.api.dto.UserDTO;
import com.springboot.myspringbootframework.domain.user.entities.User;
import com.springboot.myspringbootframework.domain.user.service.UserService;
import com.springboot.myspringbootframework.domain.user.utils.Convertors;
import com.springboot.myspringbootframework.web.aspect.LogAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UserApiImpl implements UserApi {

    @Autowired
    UserService userService;

    @LogAspect
    @Override
    public UserDTO getDemo(Integer str) {
        User user = userService.getUser(str);
        return Convertors.User2UserDTO(user);
    }

    @Override
    @Cacheable
    public List<UserDTO> getAllUsers() {
        List<User> list = userService.getAllUsers();
        return Convertors.Users2UserDTOs(list);
    }
}
